<?php
// $Id: test_form_admin_add_link.php 229 2008-03-03 13:27:42Z mikhail.miguel $

// 2007-05-18 K.OHWADA
// is_exist_rssc_module()

// 2007-02-20 K.OHWADA
// performance mode

//=========================================================
// WebLinks Module
// 2006-09-20 K.OHWADA
//=========================================================

include_once 'dev_header.php';
include_once 'test_form_class.php';

$test =& weblinks_test_form::getInstance();

dev_header();
echo "<h3>test form: admin add link</h3>\n";
echo "admin: ".$test->get_admin_uname()."<br />\n";

$link_url = WEBLINKS_URL.'/admin/link_manage.php';
$list_url = WEBLINKS_URL.'/admin/link_list.php?sortid=1';

$ret = $test->login_admin();
if ( !$ret )
{
	dev_footer();
}

//---------------------------------------------------------
// scenario 1: no banner, , no perfomance, no rss
//---------------------------------------------------------
echo "<h4>scenario 1: no banner, no perfomance, no rss</h4>\n";

$title    = $test->get_randum_title();
$banner   = '';
$rss_url  = '';
$rss_flag = 0;
$perf     = 0;

$ret = $test->admin_add_link_add_link($title, $banner, $rss_flag, $rss_url, $perf);
if ( !$ret )
{
	dev_footer();
}

if ( $test->match_return_msg( 'add link' ) )
{
	echo "<h4>Success !</h4>\n";
	echo "add link: ".$title." <br /><br />\n";
}
else
{
	echo "Error: add link form failed: <br /><hr />\n";
	echo $test->get_body() ."<br />\n";
}

//---------------------------------------------------------
// scenario 2: banner, no perfomance, no rss
//---------------------------------------------------------
echo "<h4>scenario 2: banner, no perfomance, no rss</h4>\n";

$title    = $test->get_randum_title();
$url      = "http://$title/";
$banner   = $test->get_randum_banner( 0 );
$width    = 20;	// figures image
$height   = 27;
$rss_url  = '';
$rss_flag = 0;
$perf     = 0;

$ret = $test->admin_add_link_add_link($title, $banner, $rss_flag, $rss_url, $perf);
if ( !$ret )
{
	dev_footer();
}

$ret = $test->admin_add_link_add_banner($title, $banner, $rss_flag, $rss_url);
if ( !$ret )
{
	dev_footer();
}

if ( $test->match_return_msg( 'add banner' ) )
{
	echo "<h4>Success !</h4>\n";
	echo "add link: ".$title." <br /><br />\n";

}
else
{
	echo "Error: add link form failed: <br /><hr />\n";
	echo $test->get_body() ."<br /><br />\n";
}

//---------------------------------------------------------
// scenario 3: banner, perfomance, no rss
//---------------------------------------------------------
echo "<h4>scenario 3: banner, perfomance, no rss</h4>\n";

$title    = $test->get_randum_title();
$url      = "http://$title/";
$banner   = $test->get_randum_banner( 0 );
$width    = 20;	// figures image
$height   = 27;
$rss_url  = '';
$rss_flag = 0;
$perf     = 1;

$ret = $test->admin_add_link_add_link($title, $banner, $rss_flag, $rss_url, $perf);
if ( !$ret )
{
	dev_footer();
}

$ret = $test->admin_add_link_add_banner($title, $banner, $rss_flag, $rss_url);
if ( !$ret )
{
	dev_footer();
}

$ret = $test->admin_add_link_update_cat($title, $rss_flag, $rss_url);
if ( !$ret )
{
	dev_footer();
}

if ( $test->match_return_msg( 'update cat' ) )
{
	echo "<h4>Success !</h4>\n";
	echo "add link: ".$title." <br /><br />\n";

}
else
{
	echo "Error: add link form failed: <br /><hr />\n";
	echo $test->get_body() ."<br /><br />\n";
}

//---------------------------------------------------------
// scenario 4: banner, no perfomance, rss
//---------------------------------------------------------
echo "<h4>scenario 4: banner, no perfomance, rss</h4>\n";

$title    = $test->get_randum_title();
$url      = "http://$title/";
$banner   = $test->get_randum_banner( 0 );
$rss_url  = WEBLINKS_URL.'/dev/rss_1.xml';
$rss_flag = 2;	// rss
$rdf_url  = '';
$atom_url = '';
$rssc_lid = 0;
$perf     = 0;

if ( $test->is_exist_rssc_module() )
{
	$ret = $test->admin_add_link_add_link($title, $banner, $rss_flag, $rss_url, $perf);
	if ( !$ret )
	{
		dev_footer();
	}

	$ret = $test->admin_add_link_add_banner($title, $banner, $rss_flag, $rss_url);
	if ( !$ret )
	{
		dev_footer();
	}

	$ret = $test->admin_add_link_add_rssc($title, $rss_flag, $rss_url, $rssc_lid);
	if ( !$ret )
	{
		dev_footer();
	}

	if ( $test->match_return_msg( 'refresh' ) )
	{
		echo "<h4>Success !</h4>\n";
		echo "add link: ".$title." <br /><br />\n";
	}
	else
	{
		echo "Error: add link form failed: <br /><hr />\n";
		echo $test->get_body() ."<br /><br />\n";
	}
}
else
{
	echo "Skip this test: RSSC module is not installed <br />\n";
}

//---------------------------------------------------------
// scenario 5: banner, perfomance, rss
//---------------------------------------------------------
echo "<h4>scenario 5: banner, perfomance, rss</h4>\n";

$title    = $test->get_randum_title();
$url      = "http://$title/";
$banner   = $test->get_randum_banner( 0 );
$rss_url  = WEBLINKS_URL.'/dev/rss_2.xml';
$rss_flag = 2;	// rss
$rdf_url  = '';
$atom_url = '';
$rssc_lid = 0;
$perf     = 1;

if ( $test->is_exist_rssc_module() )
{
	$ret = $test->admin_add_link_add_link($title, $banner, $rss_flag, $rss_url, $perf);
	if ( !$ret )
	{
		dev_footer();
	}

	$ret = $test->admin_add_link_add_banner($title, $banner, $rss_flag, $rss_url);
	if ( !$ret )
	{
		dev_footer();
	}

	$ret = $test->admin_add_link_update_cat($title, $rss_flag, $rss_url);
	if ( !$ret )
	{
		dev_footer();
	}

	$ret = $test->admin_add_link_add_rssc($title, $rss_flag, $rss_url, $rssc_lid);
	if ( !$ret )
	{
		dev_footer();
	}

	if ( $test->match_return_msg( 'refresh' ) )
	{
		echo "<h4>Success !</h4>\n";
		echo "add link: ".$title." <br /><br />\n";
	}
	else
	{
		echo "Error: add link form failed: <br /><hr />\n";
		echo $test->get_body() ."<br /><br />\n";
	}
}
else
{
	echo "Skip this test: RSSC module is not installed <br />\n";
}

//---------------------------------------------------------
echo '<a href="'.$list_url.'" target="_blank" >goto link list</a>'."<br />\n";
dev_footer();
// --- end of main ---

?>